<?php
            $this->headTitle($this->title);
             $this->headScript()->appendFile(Zend_Registry::get('static_path').'js/users.js');
            $this->headLink()->appendStylesheet(Zend_Registry::get('static_path').'css/user.css');
            $this->layout()->setLayout('userlayout');
?>
<div class="nav"><a href="<?php echo $this->url(array( 'controller' => 'resident', 'action'     => 'index'),'default', true) ?>" class="navlink">Control Panel</a><img src="../images/arrow.gif" class="arrow"/> View Documents</div>
<div id="userForm">
   <form name="search"  class="form" id="search" method="post" action="<?php echo $this->url(array( 'controller' => 'docs', 'action'     => 'view'),'default', true) ?>">
                <fieldset class="form">
                        <legend>Search a Document:</legend>
                        <label>Document Name:</label> <input type="text" name="_docName" value="<?php echo $this->docName ?>"/>&nbsp;&nbsp;&nbsp;
                        <label>Category:</label> <input type="text" name="_category" value="<?php echo $this->category ?>"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="submit" value="Search"/>
                         <input type="hidden" name="action" value="_search"/>
                </fieldset>
        </form>
     <?php
                          if($this->searchData !=null){?>
                            <div id="searchData">
                                 <table class='searchresult1'>
                                      <thead>
                                          <tr>
                                              <td width="40%"><a href="javascript:;" class="headerlink" id="DOC_NAME" title="Click here to sort">Document Name</a></td>
                                              <td width="10%">File Size</td>
                                              <td width="25%"><a href="javascript:;" class="headerlink" id="CATEGORY"  title="Click here to sort">Category</a></td>
                                              <td width="25%"><a href="javascript:;" class="headerlink" id="CREATED_DATE"  title="Click here to sort">Added On</a></td>
                                          </tr>
                                      </thead>
                                      <tbody>
                                          <?php foreach ($this->searchData as $data){ ?>
                                              <tr>
                                                <td><a href="../../docs/<?php echo $data->FILE_NAME  ?>"><?php echo $data->DOC_NAME  ?></a></td>
                                                <td><?php echo round((int)$data->FILE_SIZE/1000,2)  ?> MB</td>
                                                <td><?php echo $data->CATEGORY  ?></td>
                                                 <td><?php echo date('F d, Y',strtotime($data->CREATED_DATE)) ?></td>
                                              </tr>
                                           <?php  }
                                            if (sizeof($this->searchData) ==0){ ?>
                                              <tr>
                                                  <td colspan ="4">
                                                      <font color="red">No Documents found. </font>
                                                  </td>
                                              </tr>
                                       <?php      }
                                            ?>
                                     </tbody>
                                 </table>
                                 </div>
                       <form name="sort"  class="form" id="sort" method="post" action="<?php echo $this->url(array( 'controller' => 'docs', 'action'     => 'view'),'default', true) ?>">
                              <input type="hidden" name="action" value="_sort"/>
                              <input type="hidden" name="_docName" value="<?php echo $this->docName ?>"/>
                              <input type="hidden" name="_category" value="<?php echo $this->category ?>"/>
                              <input type="hidden" name="_sortBy" id="_sortBy" value=""/>
                       </form>
    <?php }
    ?>
</div>
<script>
    $(document).ready(function(){
            $(".headerlink").click(function(){
                $("form#sort>input#_sortBy").val($(this).attr('id'));
                 $("form#sort").submit();
            });
    });
</script>